
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.analysis.diffraction.tem &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.diffraction.tem</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.analysis.diffraction.tem</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>
<span class="c1"># Credit to Dr. Shyue Ping Ong for the template of the calculator</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module implements a TEM pattern calculator.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">namedtuple</span>
<span class="kn">from</span> <span class="nn">fractions</span> <span class="kn">import</span> <span class="n">Fraction</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">List</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">cast</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">lru_cache</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">scipy.constants</span> <span class="k">as</span> <span class="nn">sc</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">plotly.graph_objs</span> <span class="k">as</span> <span class="nn">go</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.diffraction.core</span> <span class="kn">import</span> <span class="n">AbstractDiffractionPatternCalculator</span>
<span class="kn">from</span> <span class="nn">pymatgen.symmetry.analyzer</span> <span class="kn">import</span> <span class="n">SpacegroupAnalyzer</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.string</span> <span class="kn">import</span> <span class="n">unicodeify_spacegroup</span><span class="p">,</span> <span class="n">latexify_spacegroup</span>

<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="vm">__file__</span><span class="p">),</span>
                       <span class="s2">&quot;atomic_scattering_params.json&quot;</span><span class="p">))</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
    <span class="n">ATOMIC_SCATTERING_PARAMS</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Frank Wan, Jason Liang&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2020, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;0.22&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Jason Liang&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;fwan@berkeley.edu, yhljason@berkeley.edu&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;03/31/2020&quot;</span>


<div class="viewcode-block" id="TEMCalculator"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator">[docs]</a><span class="k">class</span> <span class="nc">TEMCalculator</span><span class="p">(</span><span class="n">AbstractDiffractionPatternCalculator</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Computes the TEM pattern of a crystal structure for multiple Laue zones.</span>
<span class="sd">    Code partially inspired from XRD calculation implementation. X-ray factor to electron factor</span>
<span class="sd">        conversion based on the International Table of Crystallography.</span>
<span class="sd">    #TODO: Could add &quot;number of iterations&quot;, &quot;magnification&quot;, &quot;critical value of beam&quot;,</span>
<span class="sd">            &quot;twin direction&quot; for certain materials, &quot;sample thickness&quot;, and &quot;excitation error s&quot;</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">symprec</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">voltage</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">200</span><span class="p">,</span>
                 <span class="n">beam_direction</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">camera_length</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">160</span><span class="p">,</span>
                 <span class="n">debye_waller_factors</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">cs</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            symprec (float): Symmetry precision for structure refinement. If</span>
<span class="sd">                set to 0, no refinement is done. Otherwise, refinement is</span>
<span class="sd">                performed using spglib with provided precision.</span>
<span class="sd">            voltage (float): The wavelength is a function of the TEM microscope&#39;s</span>
<span class="sd">                voltage. By default, set to 200 kV. Units in kV.</span>
<span class="sd">            beam_direction (tuple): The direction of the electron beam fired onto the sample.</span>
<span class="sd">                By default, set to [0,0,1], which corresponds to the normal direction</span>
<span class="sd">                of the sample plane.</span>
<span class="sd">            camera_length (int): The distance from the sample to the projected diffraction pattern.</span>
<span class="sd">                By default, set to 160 cm. Units in cm.</span>
<span class="sd">            debye_waller_factors ({element symbol: float}): Allows the</span>
<span class="sd">                specification of Debye-Waller factors. Note that these</span>
<span class="sd">                factors are temperature dependent.</span>
<span class="sd">            cs (float): the chromatic aberration coefficient. set by default to 1 mm.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">symprec</span> <span class="o">=</span> <span class="n">symprec</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">voltage</span> <span class="o">=</span> <span class="n">voltage</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">beam_direction</span> <span class="o">=</span> <span class="n">beam_direction</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">camera_length</span> <span class="o">=</span> <span class="n">camera_length</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">debye_waller_factors</span> <span class="o">=</span> <span class="n">debye_waller_factors</span> <span class="ow">or</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cs</span> <span class="o">=</span> <span class="n">cs</span>

<div class="viewcode-block" id="TEMCalculator.wavelength_rel"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.wavelength_rel">[docs]</a>    <span class="nd">@lru_cache</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">wavelength_rel</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">float</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates the wavelength of the electron beam with relativistic kinematic effects taken</span>
<span class="sd">            into account.</span>
<span class="sd">        Args:</span>
<span class="sd">            none</span>
<span class="sd">        Returns:</span>
<span class="sd">            Relativistic Wavelength (in angstroms)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">wavelength_rel</span> <span class="o">=</span> <span class="n">sc</span><span class="o">.</span><span class="n">h</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">sc</span><span class="o">.</span><span class="n">m_e</span> <span class="o">*</span> <span class="n">sc</span><span class="o">.</span><span class="n">e</span> <span class="o">*</span> <span class="mi">1000</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">voltage</span> <span class="o">*</span>
                                        <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="p">(</span><span class="n">sc</span><span class="o">.</span><span class="n">e</span> <span class="o">*</span> <span class="mi">1000</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">voltage</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">sc</span><span class="o">.</span><span class="n">m_e</span> <span class="o">*</span> <span class="n">sc</span><span class="o">.</span><span class="n">c</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)))</span> <span class="o">*</span> <span class="p">(</span><span class="mi">10</span> <span class="o">**</span> <span class="mi">10</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">wavelength_rel</span></div>

<div class="viewcode-block" id="TEMCalculator.generate_points"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.generate_points">[docs]</a>    <span class="k">def</span> <span class="nf">generate_points</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coord_left</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="n">coord_right</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">10</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generates a bunch of 3D points that span a cube.</span>
<span class="sd">        Args:</span>
<span class="sd">            coord_left (int): The minimum coordinate value.</span>
<span class="sd">            coord_right (int): The maximum coordinate value.</span>
<span class="sd">        Returns:</span>
<span class="sd">            Numpy 2d array</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">points</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
        <span class="n">coord_values</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">coord_left</span><span class="p">,</span> <span class="n">coord_right</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">points</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">points</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">points</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">meshgrid</span><span class="p">(</span><span class="n">coord_values</span><span class="p">,</span> <span class="n">coord_values</span><span class="p">,</span> <span class="n">coord_values</span><span class="p">)</span>
        <span class="n">points_matrix</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">points</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
        <span class="n">result</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">points_matrix</span><span class="p">))</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="TEMCalculator.zone_axis_filter"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.zone_axis_filter">[docs]</a>    <span class="k">def</span> <span class="nf">zone_axis_filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">points</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">laue_zone</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">]]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Filters out all points that exist within the specified Laue zone according to the zone axis rule.</span>
<span class="sd">        Args:</span>
<span class="sd">            points (np.ndarray): The list of points to be filtered.</span>
<span class="sd">            laue_zone (int): The desired Laue zone.</span>
<span class="sd">        Returns:</span>
<span class="sd">            list of 3-tuples</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">points</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">points</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">points</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[]</span>
        <span class="n">filtered</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">beam_direction</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">points</span><span class="p">))</span> <span class="o">==</span> <span class="n">laue_zone</span><span class="p">)</span>
        <span class="n">result</span> <span class="o">=</span> <span class="n">points</span><span class="p">[</span><span class="n">filtered</span><span class="p">]</span>
        <span class="n">result_tuples</span> <span class="o">=</span> <span class="n">cast</span><span class="p">(</span><span class="n">List</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">]],</span> <span class="p">[</span><span class="nb">tuple</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">result</span><span class="o">.</span><span class="n">tolist</span><span class="p">()])</span>
        <span class="k">return</span> <span class="n">result_tuples</span></div>

<div class="viewcode-block" id="TEMCalculator.get_interplanar_spacings"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.get_interplanar_spacings">[docs]</a>    <span class="k">def</span> <span class="nf">get_interplanar_spacings</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">points</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">]])</span> \
            <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): the input structure.</span>
<span class="sd">            points (tuple): the desired hkl indices.</span>
<span class="sd">        Returns:</span>
<span class="sd">            Dict of hkl to its interplanar spacing, in angstroms (float).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">points_filtered</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">zone_axis_filter</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="k">if</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">in</span> <span class="n">points_filtered</span><span class="p">:</span>
            <span class="n">points_filtered</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
        <span class="n">interplanar_spacings_val</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">d_hkl</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">points_filtered</span><span class="p">)))</span>
        <span class="n">interplanar_spacings</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">points_filtered</span><span class="p">,</span> <span class="n">interplanar_spacings_val</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">interplanar_spacings</span></div>

<div class="viewcode-block" id="TEMCalculator.bragg_angles"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.bragg_angles">[docs]</a>    <span class="k">def</span> <span class="nf">bragg_angles</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">interplanar_spacings</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets the Bragg angles for every hkl point passed in (where n = 1).</span>
<span class="sd">        Args:</span>
<span class="sd">            interplanar_spacings (dict): dictionary of hkl to interplanar spacing</span>
<span class="sd">        Returns:</span>
<span class="sd">            dict of hkl plane (3-tuple) to Bragg angle in radians (float)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">plane</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">interplanar_spacings</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
        <span class="n">interplanar_spacings_val</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">interplanar_spacings</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
        <span class="n">bragg_angles_val</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arcsin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">wavelength_rel</span><span class="p">()</span> <span class="o">/</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">interplanar_spacings_val</span><span class="p">))</span>
        <span class="n">bragg_angles</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">plane</span><span class="p">,</span> <span class="n">bragg_angles_val</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">bragg_angles</span></div>

<div class="viewcode-block" id="TEMCalculator.get_s2"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.get_s2">[docs]</a>    <span class="k">def</span> <span class="nf">get_s2</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates the s squared parameter (= square of sin theta over lambda) for each hkl plane.</span>
<span class="sd">        Args:</span>
<span class="sd">            bragg_angles (Dict): The bragg angles for each hkl plane.</span>
<span class="sd">        Returns:</span>
<span class="sd">            Dict of hkl plane to s2 parameter, calculates the s squared parameter</span>
<span class="sd">                (= square of sin theta over lambda).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">plane</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">bragg_angles</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
        <span class="n">bragg_angles_val</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">bragg_angles</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
        <span class="n">s2_val</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">bragg_angles_val</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">wavelength_rel</span><span class="p">())</span> <span class="o">**</span> <span class="mi">2</span>
        <span class="n">s2</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">plane</span><span class="p">,</span> <span class="n">s2_val</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">s2</span></div>

<div class="viewcode-block" id="TEMCalculator.x_ray_factors"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.x_ray_factors">[docs]</a>    <span class="k">def</span> <span class="nf">x_ray_factors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">]]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates x-ray factors, which are required to calculate atomic scattering factors. Method partially inspired</span>
<span class="sd">        by the equivalent process in the xrd module.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            bragg_angles (Dict): Dictionary of hkl plane to Bragg angle.</span>
<span class="sd">        Returns:</span>
<span class="sd">            dict of atomic symbol to another dict of hkl plane to x-ray factor (in angstroms).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">x_ray_factors</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">s2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_s2</span><span class="p">(</span><span class="n">bragg_angles</span><span class="p">)</span>
        <span class="n">atoms</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">elements</span>
        <span class="n">scattering_factors_for_atom</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">atom</span> <span class="ow">in</span> <span class="n">atoms</span><span class="p">:</span>
            <span class="n">coeffs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ATOMIC_SCATTERING_PARAMS</span><span class="p">[</span><span class="n">atom</span><span class="o">.</span><span class="n">symbol</span><span class="p">])</span>
            <span class="k">for</span> <span class="n">plane</span> <span class="ow">in</span> <span class="n">bragg_angles</span><span class="p">:</span>
                <span class="n">scattering_factor_curr</span> <span class="o">=</span> <span class="n">atom</span><span class="o">.</span><span class="n">Z</span> <span class="o">-</span> <span class="mf">41.78214</span> <span class="o">*</span> <span class="n">s2</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">coeffs</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
                                                                                <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">coeffs</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">s2</span><span class="p">[</span><span class="n">plane</span><span class="p">]),</span>
                                                                                <span class="n">axis</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
                <span class="n">scattering_factors_for_atom</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span> <span class="o">=</span> <span class="n">scattering_factor_curr</span>
            <span class="n">x_ray_factors</span><span class="p">[</span><span class="n">atom</span><span class="o">.</span><span class="n">symbol</span><span class="p">]</span> <span class="o">=</span> <span class="n">scattering_factors_for_atom</span>
            <span class="n">scattering_factors_for_atom</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">return</span> <span class="n">x_ray_factors</span></div>

<div class="viewcode-block" id="TEMCalculator.electron_scattering_factors"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.electron_scattering_factors">[docs]</a>    <span class="k">def</span> <span class="nf">electron_scattering_factors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">]]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates atomic scattering factors for electrons using the Mott-Bethe formula (1st order Born approximation).</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            bragg_angles (dict of 3-tuple to float): The Bragg angles for each hkl plane.</span>
<span class="sd">        Returns:</span>
<span class="sd">            dict from atomic symbol to another dict of hkl plane to factor (in angstroms)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">electron_scattering_factors</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">x_ray_factors</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">x_ray_factors</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">)</span>
        <span class="n">s2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_s2</span><span class="p">(</span><span class="n">bragg_angles</span><span class="p">)</span>
        <span class="n">atoms</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">elements</span>
        <span class="n">prefactor</span> <span class="o">=</span> <span class="mf">0.023934</span>
        <span class="n">scattering_factors_for_atom</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">atom</span> <span class="ow">in</span> <span class="n">atoms</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">plane</span> <span class="ow">in</span> <span class="n">bragg_angles</span><span class="p">:</span>
                <span class="n">scattering_factor_curr</span> <span class="o">=</span> <span class="n">prefactor</span> <span class="o">*</span> <span class="p">(</span><span class="n">atom</span><span class="o">.</span><span class="n">Z</span> <span class="o">-</span> <span class="n">x_ray_factors</span><span class="p">[</span><span class="n">atom</span><span class="o">.</span><span class="n">symbol</span><span class="p">][</span><span class="n">plane</span><span class="p">])</span> <span class="o">/</span> <span class="n">s2</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span>
                <span class="n">scattering_factors_for_atom</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span> <span class="o">=</span> <span class="n">scattering_factor_curr</span>
            <span class="n">electron_scattering_factors</span><span class="p">[</span><span class="n">atom</span><span class="o">.</span><span class="n">symbol</span><span class="p">]</span> <span class="o">=</span> <span class="n">scattering_factors_for_atom</span>
            <span class="n">scattering_factors_for_atom</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">return</span> <span class="n">electron_scattering_factors</span></div>

<div class="viewcode-block" id="TEMCalculator.cell_scattering_factors"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.cell_scattering_factors">[docs]</a>    <span class="k">def</span> <span class="nf">cell_scattering_factors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">int</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates the scattering factor for the whole cell.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            bragg_angles (dict of 3-tuple to float): The Bragg angles for each hkl plane.</span>
<span class="sd">        Returns:</span>
<span class="sd">            dict of hkl plane (3-tuple) to scattering factor (in angstroms).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cell_scattering_factors</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">electron_scattering_factors</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">electron_scattering_factors</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">)</span>
        <span class="n">scattering_factor_curr</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">plane</span> <span class="ow">in</span> <span class="n">bragg_angles</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">structure</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">sp</span><span class="p">,</span> <span class="n">occu</span> <span class="ow">in</span> <span class="n">site</span><span class="o">.</span><span class="n">species</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">g_dot_r</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">plane</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">))</span>
                    <span class="n">scattering_factor_curr</span> <span class="o">+=</span> <span class="n">electron_scattering_factors</span><span class="p">[</span><span class="n">sp</span><span class="o">.</span><span class="n">symbol</span><span class="p">][</span><span class="n">plane</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span>
                        <span class="mi">2</span><span class="n">j</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">g_dot_r</span><span class="p">)</span>
            <span class="n">cell_scattering_factors</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span> <span class="o">=</span> <span class="n">scattering_factor_curr</span>
            <span class="n">scattering_factor_curr</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">return</span> <span class="n">cell_scattering_factors</span></div>

<div class="viewcode-block" id="TEMCalculator.cell_intensity"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.cell_intensity">[docs]</a>    <span class="k">def</span> <span class="nf">cell_intensity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates cell intensity for each hkl plane. For simplicity&#39;s sake, take I = |F|**2.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            bragg_angles (dict of 3-tuple to float): The Bragg angles for each hkl plane.</span>
<span class="sd">        Returns:</span>
<span class="sd">            dict of hkl plane to cell intensity</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">csf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cell_scattering_factors</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">)</span>
        <span class="n">plane</span> <span class="o">=</span> <span class="n">bragg_angles</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
        <span class="n">csf_val</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">csf</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
        <span class="n">cell_intensity_val</span> <span class="o">=</span> <span class="p">(</span><span class="n">csf_val</span> <span class="o">*</span> <span class="n">csf_val</span><span class="o">.</span><span class="n">conjugate</span><span class="p">())</span><span class="o">.</span><span class="n">real</span>
        <span class="n">cell_intensity</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">plane</span><span class="p">,</span> <span class="n">cell_intensity_val</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">cell_intensity</span></div>

<div class="viewcode-block" id="TEMCalculator.get_pattern"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.get_pattern">[docs]</a>    <span class="k">def</span> <span class="nf">get_pattern</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">scaled</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">two_theta_range</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">float</span><span class="p">,</span> <span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> \
            <span class="o">-&gt;</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns all relevant TEM DP info in a pandas dataframe.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            scaled (boolean): Required value for inheritance, does nothing in TEM pattern</span>
<span class="sd">            two_theta_range (Tuple): Required value for inheritance, does nothing in TEM pattern</span>
<span class="sd">        Returns:</span>
<span class="sd">            PandasDataFrame</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">symprec</span><span class="p">:</span>
            <span class="n">finder</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">symprec</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">symprec</span><span class="p">)</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="n">finder</span><span class="o">.</span><span class="n">get_refined_structure</span><span class="p">()</span>
        <span class="n">points</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_points</span><span class="p">(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="mi">11</span><span class="p">)</span>
        <span class="n">tem_dots</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tem_dots</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">points</span><span class="p">)</span>
        <span class="n">field_names</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;Position&quot;</span><span class="p">,</span> <span class="s2">&quot;(hkl)&quot;</span><span class="p">,</span> <span class="s2">&quot;Intensity (norm)&quot;</span><span class="p">,</span> <span class="s2">&quot;Film radius&quot;</span><span class="p">,</span> <span class="s2">&quot;Interplanar Spacing&quot;</span><span class="p">]</span>
        <span class="n">rows_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">dot</span> <span class="ow">in</span> <span class="n">tem_dots</span><span class="p">:</span>
            <span class="n">dict1</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;Pos&#39;</span><span class="p">:</span> <span class="n">dot</span><span class="o">.</span><span class="n">position</span><span class="p">,</span> <span class="s1">&#39;(hkl)&#39;</span><span class="p">:</span> <span class="n">dot</span><span class="o">.</span><span class="n">hkl</span><span class="p">,</span> <span class="s1">&#39;Intnsty (norm)&#39;</span><span class="p">:</span> <span class="n">dot</span><span class="o">.</span><span class="n">intensity</span><span class="p">,</span>
                     <span class="s1">&#39;Film rad&#39;</span><span class="p">:</span> <span class="n">dot</span><span class="o">.</span><span class="n">film_radius</span><span class="p">,</span> <span class="s1">&#39;Interplanar Spacing&#39;</span><span class="p">:</span> <span class="n">dot</span><span class="o">.</span><span class="n">d_spacing</span><span class="p">}</span>
            <span class="n">rows_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dict1</span><span class="p">)</span>
        <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">rows_list</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">field_names</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">df</span></div>

<div class="viewcode-block" id="TEMCalculator.normalized_cell_intensity"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.normalized_cell_intensity">[docs]</a>    <span class="k">def</span> <span class="nf">normalized_cell_intensity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Normalizes the cell_intensity dict to 1, for use in plotting.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            bragg_angles (dict of 3-tuple to float): The Bragg angles for each hkl plane.</span>
<span class="sd">        Returns:</span>
<span class="sd">            dict of hkl plane to normalized cell intensity</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">normalized_cell_intensity</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">cell_intensity</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cell_intensity</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">)</span>
        <span class="n">max_intensity</span> <span class="o">=</span> <span class="nb">max</span><span class="p">([</span><span class="n">v</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">cell_intensity</span><span class="o">.</span><span class="n">values</span><span class="p">()])</span>
        <span class="n">norm_factor</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="n">max_intensity</span>
        <span class="k">for</span> <span class="n">plane</span> <span class="ow">in</span> <span class="n">cell_intensity</span><span class="p">:</span>
            <span class="n">normalized_cell_intensity</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span> <span class="o">=</span> <span class="n">cell_intensity</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span> <span class="o">*</span> <span class="n">norm_factor</span>
        <span class="k">return</span> <span class="n">normalized_cell_intensity</span></div>

<div class="viewcode-block" id="TEMCalculator.is_parallel"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.is_parallel">[docs]</a>    <span class="k">def</span> <span class="nf">is_parallel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">plane</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="n">other_plane</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Checks if two hkl planes are parallel in reciprocal space.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            plane (3-tuple): The first plane to be compared.</span>
<span class="sd">            other_plane (3-tuple): The other plane to be compared.</span>
<span class="sd">        Returns:</span>
<span class="sd">            boolean</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">phi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_interplanar_angle</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">plane</span><span class="p">,</span> <span class="n">other_plane</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">phi</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">180</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span></div>

<div class="viewcode-block" id="TEMCalculator.get_first_point"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.get_first_point">[docs]</a>    <span class="k">def</span> <span class="nf">get_first_point</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">points</span><span class="p">:</span> <span class="nb">list</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">float</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets the first point to be plotted in the 2D DP, corresponding to maximum d/minimum R.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            points (list): All points to be checked.</span>
<span class="sd">        Returns:</span>
<span class="sd">            dict of a hkl plane to max interplanar distance.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">max_d</span> <span class="o">=</span> <span class="o">-</span><span class="mf">100.0</span>
        <span class="n">max_d_plane</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">points</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">zone_axis_filter</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="n">spacings</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_interplanar_spacings</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">points</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">plane</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">spacings</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
            <span class="k">if</span> <span class="n">spacings</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">max_d</span><span class="p">:</span>
                <span class="n">max_d_plane</span> <span class="o">=</span> <span class="n">plane</span>
                <span class="n">max_d</span> <span class="o">=</span> <span class="n">spacings</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">max_d_plane</span><span class="p">:</span> <span class="n">max_d</span><span class="p">}</span></div>

<div class="viewcode-block" id="TEMCalculator.get_interplanar_angle"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.get_interplanar_angle">[docs]</a>    <span class="k">def</span> <span class="nf">get_interplanar_angle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">p1</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="n">p2</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="nb">float</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the interplanar angle (in degrees) between the normal of two crystal planes.</span>
<span class="sd">        Formulas from International Tables for Crystallography Volume C pp. 2-9.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            p1 (3-tuple): plane 1</span>
<span class="sd">            p2 (3-tuple): plane 2</span>
<span class="sd">        Returns:</span>
<span class="sd">            float</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">c</span>
        <span class="n">alpha</span><span class="p">,</span> <span class="n">beta</span><span class="p">,</span> <span class="n">gamma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">deg2rad</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">alpha</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">deg2rad</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">beta</span><span class="p">),</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">deg2rad</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">gamma</span><span class="p">)</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">volume</span>
        <span class="n">a_star</span> <span class="o">=</span> <span class="n">b</span> <span class="o">*</span> <span class="n">c</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">/</span> <span class="n">v</span>
        <span class="n">b_star</span> <span class="o">=</span> <span class="n">a</span> <span class="o">*</span> <span class="n">c</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">beta</span><span class="p">)</span> <span class="o">/</span> <span class="n">v</span>
        <span class="n">c_star</span> <span class="o">=</span> <span class="n">a</span> <span class="o">*</span> <span class="n">b</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">gamma</span><span class="p">)</span> <span class="o">/</span> <span class="n">v</span>
        <span class="n">cos_alpha_star</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">beta</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">gamma</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">alpha</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">beta</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">gamma</span><span class="p">))</span>
        <span class="n">cos_beta_star</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">gamma</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">beta</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">gamma</span><span class="p">))</span>
        <span class="n">cos_gamma_star</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">beta</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">gamma</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">alpha</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">beta</span><span class="p">))</span>
        <span class="n">r1_norm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span>
            <span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">a_star</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">b_star</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">p1</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">c_star</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="o">*</span> <span class="n">a_star</span> <span class="o">*</span> <span class="n">b_star</span> <span class="o">*</span> <span class="n">cos_gamma_star</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">p1</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">a_star</span> <span class="o">*</span> <span class="n">c_star</span>
            <span class="o">*</span> <span class="n">cos_beta_star</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">p1</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">b_star</span> <span class="o">*</span> <span class="n">c_star</span> <span class="o">*</span> <span class="n">cos_gamma_star</span>
        <span class="p">)</span>
        <span class="n">r2_norm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span>
            <span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">a_star</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">b_star</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">p2</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">c_star</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="o">*</span> <span class="n">a_star</span> <span class="o">*</span> <span class="n">b_star</span> <span class="o">*</span> <span class="n">cos_gamma_star</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">a_star</span> <span class="o">*</span> <span class="n">c_star</span>
            <span class="o">*</span> <span class="n">cos_beta_star</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">b_star</span> <span class="o">*</span> <span class="n">c_star</span> <span class="o">*</span> <span class="n">cos_gamma_star</span>
        <span class="p">)</span>
        <span class="n">r1_dot_r2</span> <span class="o">=</span> <span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">a_star</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">b_star</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">p1</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">c_star</span> <span class="o">**</span> <span class="mi">2</span> \
            <span class="o">+</span> <span class="p">(</span><span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="n">a_star</span> <span class="o">*</span> <span class="n">b_star</span> <span class="o">*</span> <span class="n">cos_gamma_star</span> \
            <span class="o">+</span> <span class="p">(</span><span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="n">a_star</span> <span class="o">*</span> <span class="n">c_star</span> <span class="o">*</span> <span class="n">cos_beta_star</span> \
            <span class="o">+</span> <span class="p">(</span><span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">p2</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">p1</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">*</span> <span class="n">b_star</span> <span class="o">*</span> <span class="n">c_star</span> <span class="o">*</span> <span class="n">cos_alpha_star</span>
        <span class="n">phi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arccos</span><span class="p">(</span><span class="n">r1_dot_r2</span> <span class="o">/</span> <span class="p">(</span><span class="n">r1_norm</span> <span class="o">*</span> <span class="n">r2_norm</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">rad2deg</span><span class="p">(</span><span class="n">phi</span><span class="p">)</span></div>

<div class="viewcode-block" id="TEMCalculator.get_plot_coeffs"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.get_plot_coeffs">[docs]</a>    <span class="k">def</span> <span class="nf">get_plot_coeffs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p1</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="n">p2</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="n">p3</span><span class="p">:</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">])</span> \
            <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates coefficients of the vector addition required to generate positions for each DP point</span>
<span class="sd">        by the Moore-Penrose inverse method.</span>
<span class="sd">        Args:</span>
<span class="sd">            p1 (3-tuple): The first point. Fixed.</span>
<span class="sd">            p2 (3-tuple): The second point. Fixed.</span>
<span class="sd">            p3 (3-tuple): The point whose coefficients are to be calculted.</span>
<span class="sd">        Returns:</span>
<span class="sd">            Numpy array</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="n">p1</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">p2</span><span class="p">[</span><span class="mi">0</span><span class="p">]],</span>
                      <span class="p">[</span><span class="n">p1</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">p2</span><span class="p">[</span><span class="mi">1</span><span class="p">]],</span>
                      <span class="p">[</span><span class="n">p1</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">p2</span><span class="p">[</span><span class="mi">2</span><span class="p">]]])</span>
        <span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="n">p3</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">p3</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">p3</span><span class="p">[</span><span class="mi">2</span><span class="p">]]])</span><span class="o">.</span><span class="n">T</span>
        <span class="n">a_pinv</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">pinv</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">a_pinv</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="n">x</span><span class="p">)</span></div>

<div class="viewcode-block" id="TEMCalculator.get_positions"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.get_positions">[docs]</a>    <span class="k">def</span> <span class="nf">get_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">points</span><span class="p">:</span> <span class="nb">list</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">],</span> <span class="nb">list</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates all the positions of each hkl point in the 2D diffraction pattern by vector addition.</span>
<span class="sd">        Distance in centimeters.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            points (list): All points to be checked.</span>
<span class="sd">        Returns:</span>
<span class="sd">            dict of hkl plane to xy-coordinates.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">positions</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">points</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">zone_axis_filter</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="c1"># first is the max_d, min_r</span>
        <span class="n">first_point_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_first_point</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">points</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">point</span> <span class="ow">in</span> <span class="n">first_point_dict</span><span class="p">:</span>
            <span class="n">first_point</span> <span class="o">=</span> <span class="n">point</span>
            <span class="n">first_d</span> <span class="o">=</span> <span class="n">first_point_dict</span><span class="p">[</span><span class="n">point</span><span class="p">]</span>
        <span class="n">spacings</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_interplanar_spacings</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">points</span><span class="p">)</span>
        <span class="c1"># second is the first non-parallel-to-first-point vector when sorted.</span>
        <span class="c1"># note 000 is &quot;parallel&quot; to every plane vector.</span>
        <span class="k">for</span> <span class="n">plane</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">spacings</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
            <span class="n">second_point</span><span class="p">,</span> <span class="n">second_d</span> <span class="o">=</span> <span class="n">plane</span><span class="p">,</span> <span class="n">spacings</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_parallel</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">first_point</span><span class="p">,</span> <span class="n">second_point</span><span class="p">):</span>
                <span class="k">break</span>
        <span class="n">p1</span> <span class="o">=</span> <span class="n">first_point</span>
        <span class="n">p2</span> <span class="o">=</span> <span class="n">second_point</span>
        <span class="k">if</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">in</span> <span class="n">points</span><span class="p">:</span>
            <span class="n">points</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
        <span class="n">points</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">first_point</span><span class="p">)</span>
        <span class="n">points</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">second_point</span><span class="p">)</span>
        <span class="n">positions</span><span class="p">[(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
        <span class="n">r1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">wavelength_rel</span><span class="p">()</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">camera_length</span> <span class="o">/</span> <span class="n">first_d</span>
        <span class="n">positions</span><span class="p">[</span><span class="n">first_point</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">r1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
        <span class="n">r2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">wavelength_rel</span><span class="p">()</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">camera_length</span> <span class="o">/</span> <span class="n">second_d</span>
        <span class="n">phi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">deg2rad</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_interplanar_angle</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">first_point</span><span class="p">,</span> <span class="n">second_point</span><span class="p">))</span>
        <span class="n">positions</span><span class="p">[</span><span class="n">second_point</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">r2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">phi</span><span class="p">),</span> <span class="n">r2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">phi</span><span class="p">)])</span>
        <span class="k">for</span> <span class="n">plane</span> <span class="ow">in</span> <span class="n">points</span><span class="p">:</span>
            <span class="n">coeffs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_plot_coeffs</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">plane</span><span class="p">)</span>
            <span class="n">pos</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">coeffs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">positions</span><span class="p">[</span><span class="n">first_point</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">coeffs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">positions</span><span class="p">[</span><span class="n">second_point</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span>
                            <span class="n">coeffs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">positions</span><span class="p">[</span><span class="n">first_point</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">coeffs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">positions</span><span class="p">[</span><span class="n">second_point</span><span class="p">][</span><span class="mi">1</span><span class="p">]])</span>
            <span class="n">positions</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span> <span class="o">=</span> <span class="n">pos</span>
        <span class="n">points</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
        <span class="n">points</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">first_point</span><span class="p">)</span>
        <span class="n">points</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">second_point</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">positions</span></div>

<div class="viewcode-block" id="TEMCalculator.tem_dots"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.tem_dots">[docs]</a>    <span class="k">def</span> <span class="nf">tem_dots</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">points</span><span class="p">:</span> <span class="nb">list</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">list</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generates all TEM_dot as named tuples that will appear on the 2D diffraction pattern.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">            points (list): All points to be checked.</span>
<span class="sd">        Returns:</span>
<span class="sd">            list of TEM_dots</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">dots</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">interplanar_spacings</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_interplanar_spacings</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">points</span><span class="p">)</span>
        <span class="n">bragg_angles</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bragg_angles</span><span class="p">(</span><span class="n">interplanar_spacings</span><span class="p">)</span>
        <span class="n">cell_intensity</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">normalized_cell_intensity</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">bragg_angles</span><span class="p">)</span>
        <span class="n">positions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_positions</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">points</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">plane</span> <span class="ow">in</span> <span class="n">cell_intensity</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">dot</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s1">&#39;TEM_dot&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;position&#39;</span><span class="p">,</span> <span class="s1">&#39;hkl&#39;</span><span class="p">,</span> <span class="s1">&#39;intensity&#39;</span><span class="p">,</span> <span class="s1">&#39;film_radius&#39;</span><span class="p">,</span> <span class="s1">&#39;d_spacing&#39;</span><span class="p">])</span>
            <span class="n">position</span> <span class="o">=</span> <span class="n">positions</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span>
            <span class="n">hkl</span> <span class="o">=</span> <span class="n">plane</span>
            <span class="n">intensity</span> <span class="o">=</span> <span class="n">cell_intensity</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span>
            <span class="n">film_radius</span> <span class="o">=</span> <span class="mf">0.91</span> <span class="o">*</span> <span class="p">(</span><span class="mi">10</span> <span class="o">**</span> <span class="o">-</span><span class="mi">3</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">cs</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">wavelength_rel</span><span class="p">()</span> <span class="o">**</span> <span class="mi">3</span><span class="p">)</span> <span class="o">**</span> <span class="n">Fraction</span><span class="p">(</span><span class="s1">&#39;1/4&#39;</span><span class="p">)</span>
            <span class="n">d_spacing</span> <span class="o">=</span> <span class="n">interplanar_spacings</span><span class="p">[</span><span class="n">plane</span><span class="p">]</span>
            <span class="n">tem_dot</span> <span class="o">=</span> <span class="n">dot</span><span class="p">(</span><span class="n">position</span><span class="p">,</span> <span class="n">hkl</span><span class="p">,</span> <span class="n">intensity</span><span class="p">,</span> <span class="n">film_radius</span><span class="p">,</span> <span class="n">d_spacing</span><span class="p">)</span>
            <span class="n">dots</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tem_dot</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">dots</span></div>

<div class="viewcode-block" id="TEMCalculator.get_plot_2d"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.get_plot_2d">[docs]</a>    <span class="k">def</span> <span class="nf">get_plot_2d</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">go</span><span class="o">.</span><span class="n">Figure</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generates the 2D diffraction pattern of the input structure.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">        Returns:</span>
<span class="sd">            Figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">symprec</span><span class="p">:</span>
            <span class="n">finder</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">symprec</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">symprec</span><span class="p">)</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="n">finder</span><span class="o">.</span><span class="n">get_refined_structure</span><span class="p">()</span>
        <span class="n">points</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_points</span><span class="p">(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="mi">11</span><span class="p">)</span>
        <span class="n">tem_dots</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tem_dots</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">points</span><span class="p">)</span>
        <span class="n">xs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">ys</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">hkls</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">intensities</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">dot</span> <span class="ow">in</span> <span class="n">tem_dots</span><span class="p">:</span>
            <span class="n">xs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">position</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">ys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">position</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">hkls</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">hkl</span><span class="p">))</span>
            <span class="n">intensities</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">intensity</span><span class="p">)</span>
        <span class="n">hkls</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">unicodeify_spacegroup</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">latexify_spacegroup</span><span class="p">,</span> <span class="n">hkls</span><span class="p">))))</span>
        <span class="n">data</span> <span class="o">=</span> <span class="p">[</span>
            <span class="n">go</span><span class="o">.</span><span class="n">Scatter</span><span class="p">(</span>
                <span class="n">x</span><span class="o">=</span><span class="n">xs</span><span class="p">,</span>
                <span class="n">y</span><span class="o">=</span><span class="n">ys</span><span class="p">,</span>
                <span class="n">text</span><span class="o">=</span><span class="n">hkls</span><span class="p">,</span>
                <span class="n">hoverinfo</span><span class="o">=</span><span class="s1">&#39;text&#39;</span><span class="p">,</span>
                <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;markers&#39;</span><span class="p">,</span>
                <span class="n">marker</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
                    <span class="n">size</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
                    <span class="n">cmax</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                    <span class="n">cmin</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                    <span class="n">color</span><span class="o">=</span><span class="n">intensities</span><span class="p">,</span>
                    <span class="n">colorscale</span><span class="o">=</span><span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;black&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="s1">&#39;white&#39;</span><span class="p">]]</span>
                <span class="p">),</span>
                <span class="n">showlegend</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="p">),</span> <span class="n">go</span><span class="o">.</span><span class="n">Scatter</span><span class="p">(</span>
                <span class="n">x</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                <span class="n">y</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                <span class="n">text</span><span class="o">=</span><span class="s2">&quot;(0, 0, 0): Direct beam&quot;</span><span class="p">,</span>
                <span class="n">hoverinfo</span><span class="o">=</span><span class="s1">&#39;text&#39;</span><span class="p">,</span>
                <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;markers&#39;</span><span class="p">,</span>
                <span class="n">marker</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
                    <span class="n">size</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span>
                    <span class="n">cmax</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                    <span class="n">cmin</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                    <span class="n">color</span><span class="o">=</span><span class="s1">&#39;white&#39;</span>
                <span class="p">),</span>
                <span class="n">showlegend</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="p">)</span>
        <span class="p">]</span>
        <span class="n">layout</span> <span class="o">=</span> <span class="n">go</span><span class="o">.</span><span class="n">Layout</span><span class="p">(</span>
            <span class="n">title</span><span class="o">=</span><span class="s1">&#39;2D Diffraction Pattern&lt;br&gt;Beam Direction: &#39;</span> <span class="o">+</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">beam_direction</span><span class="p">),</span>
            <span class="n">font</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
                <span class="n">size</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span>
                <span class="n">color</span><span class="o">=</span><span class="s1">&#39;#7f7f7f&#39;</span><span class="p">),</span>
            <span class="n">hovermode</span><span class="o">=</span><span class="s1">&#39;closest&#39;</span><span class="p">,</span>
            <span class="n">xaxis</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
                <span class="nb">range</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span>
                <span class="n">showgrid</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">zeroline</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">showline</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">ticks</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>
                <span class="n">showticklabels</span><span class="o">=</span><span class="kc">False</span>
            <span class="p">),</span>
            <span class="n">yaxis</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
                <span class="nb">range</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span>
                <span class="n">showgrid</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">zeroline</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">showline</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">ticks</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>
                <span class="n">showticklabels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="p">),</span>
            <span class="n">width</span><span class="o">=</span><span class="mi">550</span><span class="p">,</span>
            <span class="n">height</span><span class="o">=</span><span class="mi">550</span><span class="p">,</span>
            <span class="n">paper_bgcolor</span><span class="o">=</span><span class="s1">&#39;rgba(100,110,110,0.5)&#39;</span><span class="p">,</span>
            <span class="n">plot_bgcolor</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">fig</span> <span class="o">=</span> <span class="n">go</span><span class="o">.</span><span class="n">Figure</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">layout</span><span class="o">=</span><span class="n">layout</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">fig</span></div>

<div class="viewcode-block" id="TEMCalculator.get_plot_2d_concise"><a class="viewcode-back" href="../../../../pymatgen.analysis.diffraction.tem.html#pymatgen.analysis.diffraction.tem.TEMCalculator.get_plot_2d_concise">[docs]</a>    <span class="k">def</span> <span class="nf">get_plot_2d_concise</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">go</span><span class="o">.</span><span class="n">Figure</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generates the concise 2D diffraction pattern of the input structure of a smaller size and without layout.</span>
<span class="sd">        Does not display.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): The input structure.</span>
<span class="sd">        Returns:</span>
<span class="sd">            Figure</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">symprec</span><span class="p">:</span>
            <span class="n">finder</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">symprec</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">symprec</span><span class="p">)</span>
            <span class="n">structure</span> <span class="o">=</span> <span class="n">finder</span><span class="o">.</span><span class="n">get_refined_structure</span><span class="p">()</span>
        <span class="n">points</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">generate_points</span><span class="p">(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="mi">11</span><span class="p">)</span>
        <span class="n">tem_dots</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tem_dots</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">points</span><span class="p">)</span>
        <span class="n">xs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">ys</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">hkls</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">intensities</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">dot</span> <span class="ow">in</span> <span class="n">tem_dots</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">dot</span><span class="o">.</span><span class="n">hkl</span> <span class="o">!=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span>
                <span class="n">xs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">position</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">ys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">position</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">hkls</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">hkl</span><span class="p">)</span>
                <span class="n">intensities</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">intensity</span><span class="p">)</span>
        <span class="n">data</span> <span class="o">=</span> <span class="p">[</span>
            <span class="n">go</span><span class="o">.</span><span class="n">Scatter</span><span class="p">(</span>
                <span class="n">x</span><span class="o">=</span><span class="n">xs</span><span class="p">,</span>
                <span class="n">y</span><span class="o">=</span><span class="n">ys</span><span class="p">,</span>
                <span class="n">text</span><span class="o">=</span><span class="n">hkls</span><span class="p">,</span>
                <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;markers&#39;</span><span class="p">,</span>
                <span class="n">hoverinfo</span><span class="o">=</span><span class="s1">&#39;skip&#39;</span><span class="p">,</span>
                <span class="n">marker</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
                    <span class="n">size</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span>
                    <span class="n">cmax</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
                    <span class="n">cmin</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
                    <span class="n">color</span><span class="o">=</span><span class="n">intensities</span><span class="p">,</span>
                    <span class="n">colorscale</span><span class="o">=</span><span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;black&#39;</span><span class="p">],</span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="s1">&#39;white&#39;</span><span class="p">]]</span>
                <span class="p">),</span>
                <span class="n">showlegend</span><span class="o">=</span><span class="kc">False</span>
            <span class="p">)</span>
        <span class="p">]</span>
        <span class="n">layout</span> <span class="o">=</span> <span class="n">go</span><span class="o">.</span><span class="n">Layout</span><span class="p">(</span>
            <span class="n">xaxis</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
                <span class="nb">range</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span>
                <span class="n">showgrid</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">zeroline</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">showline</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">ticks</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>
                <span class="n">showticklabels</span><span class="o">=</span><span class="kc">False</span>
            <span class="p">),</span>
            <span class="n">yaxis</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
                <span class="nb">range</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span>
                <span class="n">showgrid</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">zeroline</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">showline</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                <span class="n">ticks</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>
                <span class="n">showticklabels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="p">),</span>
            <span class="n">plot_bgcolor</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span>
            <span class="n">margin</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;l&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;t&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">},</span>
            <span class="n">width</span><span class="o">=</span><span class="mi">121</span><span class="p">,</span>
            <span class="n">height</span><span class="o">=</span><span class="mi">121</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">fig</span> <span class="o">=</span> <span class="n">go</span><span class="o">.</span><span class="n">Figure</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">layout</span><span class="o">=</span><span class="n">layout</span><span class="p">)</span>
        <span class="n">fig</span><span class="o">.</span><span class="n">layout</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">showlegend</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">fig</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.diffraction.tem</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>